home *** CD-ROM | disk | FTP | other *** search
/ PC Media 2 / PC MEDIA CD02.iso / share / prog / realasm1 / ftadd.asm < prev    next >
Encoding:
Assembly Source File  |  1993-07-17  |  5.1 KB  |  129 lines

  1. .286
  2. ;================================================
  3. ; Adds REAL10's dst, src
  4. ;
  5. ;------------------------------------------------
  6. cseg          segment word public 'code'
  7.               assume  cs:cseg,ss:cseg
  8.               assume  ds:cseg,es:cseg
  9.  
  10.               include math.inc
  11.  
  12. ftadd         proc    near  dst:NPR10, src:NPR10
  13.               local   dcopy[24]:BYTE, scopy[24]:BYTE, exp:SWORD
  14.  
  15.               pusha
  16.               mov     di, dst
  17.               mov     si, src
  18.  
  19.               invoke  ftzero, si                ; src = 0.0 ?
  20.               .IF ax == TRUE                    ;
  21.                  jmp     exit                   ; dst unchanged
  22.               .ENDIF                            ;
  23.  
  24.               invoke  ftzero, di                ; dst = 0.0 ?
  25.               .IF ax == TRUE                    ;
  26.                  invoke  movx, di, si, 5        ; dst = src
  27.                  jmp     exit                   ;
  28.               .ENDIF                            ;
  29.  
  30.               invoke  clrx, addr dcopy, 12      ;
  31.               invoke  movx, addr dcopy[8], di, 4  ;
  32.               mov     ax, word ptr [di]+8    ;
  33.               mov     cl, ah                    ;
  34.               and     cl, 80h                   ;
  35.               rol     cl, 1                     ; cl = sign of dst
  36.               and     ax, 7fffh                 ;
  37.               sub     ax, 3fffh                 ;
  38.               mov     exp, ax                   ;
  39.  
  40.               .WHILE (exp > 0)                  ;
  41.               dec     exp                       ;
  42.               invoke  lshx, addr dcopy, 12      ;
  43.               .ENDW                             ;
  44.  
  45.               .WHILE (exp < 0)                  ;
  46.               inc     exp                       ;
  47.               invoke  rshx, addr dcopy, 12      ;
  48.               .ENDW                             ;
  49.  
  50.               invoke  clrx, addr scopy, 12      ;
  51.               invoke  movx, addr scopy[8], si, 4 ;
  52.               mov     ax, word ptr [si]+8       ;
  53.               mov     ch, ah                    ;
  54.               and     ch, 80h                   ;
  55.               rol     ch, 1                     ; ch = sign of src
  56.               and     ax, 7fffh                 ;
  57.               sub     ax, 3fffh                 ;
  58.               mov     exp, ax                   ;
  59.  
  60.               .WHILE (exp > 0)                  ;
  61.               dec     exp                       ;
  62.               invoke  lshx, addr scopy, 12      ;
  63.               .ENDW                             ;
  64.  
  65.               .WHILE (exp < 0)                  ;
  66.               inc     exp                       ;
  67.               invoke  rshx, addr scopy, 12      ;
  68.               .ENDW                             ;
  69.  
  70.               mov     dx, word ptr es:[di]+8    ;
  71.               and     dx, 8000h                 ; preserve sign of dst
  72.               add     dx, 3fffh                 ; exponent = 0
  73.  
  74. ;------------------------------------------------
  75. ; add equal signs
  76. ;------------------------------------------------
  77.               .IF     ((cx == 101h) || (cx == 0))
  78.                  invoke  addx, addr dcopy, addr scopy, 12
  79.  
  80. ;------------------------------------------------
  81. ; subtract unequal signs
  82. ;------------------------------------------------
  83.               .ELSEIF ((cx == 100h) || (cx == 1))
  84.                  invoke  cmpx, addr dcopy, addr scopy, 12
  85.  
  86.                  .IF ax == 0                    ; if equal
  87.                     invoke  clrx, di, 5         ;
  88.                     jmp     exit                ; dst = 0.0
  89.  
  90.                  .ELSEIF ax == 1                ; if dcopy > scopy
  91.                     invoke  subx, addr dcopy, addr scopy, 12
  92.                     .IF cx == 100h              ; if +dst > -src
  93.                        and     dx, 7fffh        ; +ve result
  94.                     .ELSEIF cx == 1             ; if -dst > +src
  95.                        or      dx, 8000h        ; -ve result
  96.                     .ENDIF
  97.  
  98.                  .ELSEIF ax == -1               ; if dcopy < scopy
  99.                     invoke  subx, addr scopy, addr dcopy, 12
  100.                     invoke  movx, addr dcopy, addr scopy, 12
  101.  
  102.                     .IF cx == 100h              ; if +dst < -src
  103.                        or      dx, 8000h        ; -ve result
  104.                     .ELSEIF cx == 1             ; if -dst < +src
  105.                        and     dx, 7fffh        ; +ve result
  106.                     .ENDIF
  107.  
  108.                  .ENDIF
  109.               .ENDIF
  110.  
  111.               add     dx, 64                    ; max exponent
  112.               .WHILE (1)                        ; normalise dcopy
  113.                  mov     ax, word ptr dcopy[22] ;
  114.                  .BREAK .IF (ax & 8000h)        ;
  115.                  invoke  lshx, addr dcopy, 12   ;
  116.                  dec     dx                     ; exponent--
  117.               .ENDW                             ;
  118.  
  119.               mov     word ptr [di]+8, dx       ;
  120.               invoke  movx, di, addr dcopy[16], 4
  121. exit:
  122.               popa
  123.  
  124.               ret
  125. ftadd         endp
  126.  
  127. cseg          ends
  128.               end
  129.